package org.addressBook.servlet;

import com.google.gson.Gson;
import org.addressBook.bean.TableData;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SaveTableServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json");
        Gson gson = new Gson();

        try{
            StringBuilder sb = new StringBuilder();
            String s;
            while((s = request.getReader().readLine())!=null){
                sb.append(s);
            }
            TableData tableData = (TableData) gson.fromJson(sb.toString(), TableData.class);
            System.out.println(tableData);
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
